(function(win, $){
    var getEditorPT = win.getEditorPT = function() {
        var data = $('#activity_intro').val();
        if(!data) {
            return [];
        }
        data = $.parseJSON(data);
        //console.log(data);
        return data;
    };
    var setEditorPT = win.setEditorPT = function(data) {
        //console.log(data);
        if($.isArray(data) && data.length > 0) {
            $('#activity_intro').val(JSON.stringify(data));
            var viewObj = $('#box_intro_view');
            editorPTView(viewObj, data, domainPic);
            $('#but_intro_update').removeClass('hide');
            $('#but_intro_add').addClass('hide');
        }
        layer.closeAll();
    };
    function showEditorPT() {
        layer.open({
            type: 2,
            title: '详细介绍编辑',
            shadeClose: false,
            shade: 0.8,
            area: ['1250px', '95%'],
            content: urlEditorPT + '?type=activity'
        });
    }
    var setFormResult = win.setFormResult = function (data) {
        //console.log(data);
        layer.closeAll();
        if(data.status != 10000) {
            layer.alert(data.errmsg, {icon: 5});
        } else {
            layer.confirm('更新成功！', {icon: 6, title:'系统提示', btn:'查看列表'}, function(index){
            	location.href = urlList;
            });
        }
    }
    function initCover() {
        var boxShow = $('#box_cover_show');
        var boxUpdate = $('#box_cover_update');
        var funcInputFile = function() {
        	//<p class="help-block">图片高宽都必须是：750x220px，大小不得超过2M</p>
            var inputBox = $('<div class="col-xs-10"><input type="file" class="form-control" id="activity_cover" name="activity_cover"></div>');
            var butBox = $('<div class="col-xs-2"></div>');
            var butCannel = $('<button type="button" class="btn btn-default">取消</button>');
            butCannel.on('click', funcCannel);
            butBox.append(butCannel);
            boxUpdate.append(inputBox);
            boxUpdate.append(butBox);
        };
        var funcCannel = function () {
            boxShow.removeClass('hide');
            boxUpdate.addClass('hide');
            boxUpdate.html('');
        };
        $('#but_cover_update').on('click', function(){
            funcInputFile();
            boxShow.addClass('hide');
            boxUpdate.removeClass('hide');
        });
    }
    $(function(){

    	
        initCover();
        //$('#but_intro_add').on('click', showEditorPT);
        //$('#but_intro_update').on('click', showEditorPT);
        $('#form_update').on('valid.form', function(e, form){
            layer.load();
            form.submit();
        });
        //var viewObj = $('#box_intro_view');
       // var data = getEditorPT();
       // editorPTView(viewObj, data, domainPic);



        $('#choose input').click(function(){
            var self = $(this),
                indexI = $(this).index();
            self.addClass("active").siblings().removeClass("active");
            $(".choose-tab .tabs").eq(indexI).addClass("show").siblings().removeClass("show");
        })
    });
})(window, jQuery);



//实例化编辑器
//建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
var ue = UE.getEditor('editor');


$('#posion_banner').change(function() {
  var $option = $('#posion_banner option:selected').val(),
      $em = $('#imgInfo em');
  if ( $option < 5 ) {
      $em.text('750X200');
  } else if ( $option == 5) {
      $em.text('360X390');
  } else {
      $em.text('360X190');
  }
});









